home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / GLOBAL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  10.3 KB  |  455 lines

  1. #ifndef _GLOBAL_H
  2. #define    _GLOBAL_H
  3.  
  4. /* While GNU C (DJGPP on MSDOS) is the supported compiler for TNOS,
  5.    other compilers MAY work. They MUST be ANSI C compatible, that is,
  6.    they must support prototypes...
  7.  */
  8.  
  9.  
  10. #ifdef _lint
  11. #define NDEBUG
  12. #endif
  13.  
  14. #include <assert.h>
  15.  
  16. #ifndef UNIX
  17. # ifndef OPTIONAL
  18. #  define OPTIONAL
  19. # endif
  20. # define HAVE_UNISTD_H        1
  21. # define HAVE_TM_ISDST        1
  22. # define IS_LITTLE_ENDIAN    1
  23. # define TNOS_PC(p)        (p->env[0].__eip)
  24. # define TNOS_SP(p)        (p->env[0].__esp)
  25. # define TNOS_EBP(p)        (p->env[0].__ebp)
  26. #else
  27. # ifndef _SYSTEM_H
  28. # include "system.h"
  29. # endif
  30. #endif
  31.  
  32. #ifndef SYS_ERRLIST
  33. #define SYS_ERRLIST(x)        sys_errlist[x]
  34. #endif
  35.  
  36. #ifdef _lint
  37. # define IFLINT(x) x
  38. #else
  39. # define IFLINT(x)
  40. #endif
  41.  
  42.  
  43. /* Global definitions used by every source file.
  44.  * Some may be compiler dependent.
  45.  */
  46.  
  47. #ifndef _STDIO_H
  48. # include <stdio.h>
  49. #endif
  50. #undef  _STDIO_H_
  51. #define _STDIO_H_    1
  52.  
  53. #if !defined(_STDLIB_H) && !defined(__dj_include_stdlib_h_)
  54. # include <stdlib.h>
  55. #endif
  56. #undef  _STDLIB_H_
  57. #define _STDLIB_H_
  58.  
  59. #ifndef _STRING_H
  60. # include <string.h>
  61. #endif
  62. #undef  _STRING_H_
  63. #define _STRING_H_    1
  64.  
  65. #ifdef UNIX
  66. # define O_BINARY 0
  67. # ifndef _SYS_TYPES_H
  68.    /*lint -save -e10 -e19 */
  69. #  include <sys/types.h>
  70.    /*lint -restore */
  71. # endif
  72. #endif
  73.  
  74.  
  75. struct ax25_cb;
  76. struct iface;
  77. struct ip;
  78. struct mbx;
  79. struct mbuf;
  80. struct nr4cb;
  81. struct session;
  82.  
  83.  
  84. #ifndef __STR
  85. # define __STR(x)    catalog(CAT, x)
  86. #endif
  87.  
  88.  
  89. #define    READ_BINARY    "rb"
  90. #define    WRITE_BINARY    "wb"
  91. #define    APPEND_BINARY    "ab+"
  92. #ifdef MSDOS
  93. #define    READ_TEXT    "rt"
  94. #define    WRITE_TEXT    "wt"
  95. #define    APPEND_TEXT    "at+"
  96. #define UPDATE_TEXT    "rt+"
  97. #define CREATE_TEXT    "wt+"
  98. #else
  99. /* DON'T change these! Using ones with 't' make UPDATE_TEXT and
  100.    CREATE_TEXT *NOT* be able to write on some OSs! */
  101. #define    READ_TEXT    "r"
  102. #define    WRITE_TEXT    "w"
  103. #define    APPEND_TEXT    "a+"
  104. #define UPDATE_TEXT    "r+"
  105. #define CREATE_TEXT    "w+"
  106. #endif
  107.  
  108.  
  109. /* These two lines assume that your compiler's longs are 32 bits and
  110.  * shorts are 16 bits. It is already assumed that chars are 8 bits,
  111.  * but it doesn't matter if they're signed or unsigned.
  112.  */
  113. #ifdef MSDOS
  114.  typedef unsigned int uint;    /* either 16 or 32-bit unsigned integer */
  115. #endif
  116.  
  117. typedef long int32;        /* 32-bit signed integer */
  118. typedef unsigned long uint32;    /* 32-bit unsigned integer */
  119. #ifdef MSDOS
  120. typedef unsigned long long uint64; /* 64-bit unsigned integer */
  121. #endif
  122. typedef unsigned short int16;    /* 16-bit unsigned integer */
  123. typedef unsigned char byte_t;    /*  8-bit unsigned integer */
  124. typedef unsigned char uint8;    /*  8-bit unsigned integer */
  125. #define    uchar(x) ((unsigned char)(x))
  126. #define    MAXINT16 65535        /* Largest 16-bit integer */
  127. #ifdef __GNUC__
  128. # define MAXINT32 4294967295UL    /* Largest 32-bit integer */
  129. #else
  130. # define MAXINT32 4294967295L    /* Largest 32-bit integer */
  131. #endif
  132. #define    NBBY    8        /* 8 bits/byte */
  133.  
  134. #define    HASHMOD    7        /* Modulus used by hash_ip() function */
  135.  
  136.  
  137. /* Since not all compilers support structure assignment, the ASSIGN()
  138.  * macro is used. This controls how it's actually implemented.
  139.  */
  140. #ifdef    NOSTRUCTASSIGN    /* Version for old compilers that don't support it */
  141. # define ASSIGN(a,b)    memcpy((char *)&(a),(char *)&(b),sizeof(b));
  142. #else            /* Version for compilers that do */
  143. # define ASSIGN(a,b)    ((a) = (b))
  144. #endif
  145.  
  146.  
  147. /* Define null object pointer in case stdio.h isn't included */
  148. #ifndef    NULL
  149. /* General purpose NULL pointer */
  150. # define NULL (void *)0
  151. #endif
  152.  
  153. #define    NULLCHAR    (char *)0    /* Null character pointer */
  154. #define    NULLCHARP    (char **)0    /* Null character pointer pointer */
  155. #define    NULLINT        (int *)0    /* Null integer pointer */
  156. #define NULLFP(x)     (int (*)x)0
  157. #define NULLVFP(x)    (void (*)x)0
  158. #define    NULLVIFP    (void (*)())0
  159. #define    NULLFILE    (FILE *)0    /* Null file pointer */
  160.  
  161. /* standard boolean constants */
  162. #define FALSE 0
  163. #define TRUE 1
  164. #define NO 0
  165. #define YES 1
  166.  
  167. #define CTLA 0x1
  168. #define CTLB 0x2
  169. #define CTLC 0x3
  170. #define CTLD 0x4
  171. #define CTLE 0x5
  172. #define CTLF 0x6
  173. #define CTLG 0x7
  174. #define CTLH 0x8
  175. #define CTLI 0x9
  176. #define CTLJ 0xa
  177. #define CTLK 0xb
  178. #define CTLL 0xc
  179. #define CTLM 0xd
  180. #define CTLN 0xe
  181. #define CTLO 0xf
  182. #define CTLP 0x10
  183. #define CTLQ 0x11
  184. #define CTLR 0x12
  185. #define CTLS 0x13
  186. #define CTLT 0x14
  187. #define CTLU 0x15
  188. #define CTLV 0x16
  189. #define CTLW 0x17
  190. #define CTLX 0x18
  191. #define CTLY 0x19
  192. #define CTLZ 0x1a
  193.  
  194. #define    BS    CTLH
  195. #define    TAB    CTLI
  196. #define    LF    CTLJ
  197. #define    FF    CTLL
  198. #define    CR    CTLM
  199. #define    XON    CTLQ
  200. #define    XOFF    CTLS
  201. #define    ESC    0x1b
  202. #define    DEL    0x7f
  203.  
  204. #define TNOS_MUTEX_LOCKED    911
  205. #define TNOS_MUTEX_UNLOCKED    7373
  206.  
  207. #ifdef UNIX
  208.  void textattr (int color);
  209.  void textbackground (int color);
  210.  void textcolor (int color);
  211.  void textrefresh (void);
  212. # ifdef BSD_RANDOM
  213. #  define SRANDOM(n) srandom(n)
  214. #  define RANDOM(n) ((int) (random() * (n)))
  215. # else
  216. #  ifdef sun
  217.     extern double drand48(void);
  218. #  endif
  219. #  define SRANDOM(n) srand48(n)
  220. #  define RANDOM(n) ((int) (drand48() * (n)))
  221. # endif
  222.   /* !@#$%&* DOS quote-C-unquote dialects! ++bsa */
  223. # define strcmpi strcasecmp
  224. # define stricmp strcasecmp
  225. # define strncmpi strncasecmp
  226. # define strnicmp strncasecmp
  227.   /* and work around a collision which is currently making me drop core... */
  228. # undef tputs
  229. # define tputs j_tputs
  230.   /* some older systems lack strtoul(); we'll just have to hope this is okay */
  231. # ifdef NO_STRTOUL
  232. #  define strtoul(s,cp,b) ((unsigned long) strtol((s),(cp),(b)))
  233. # endif
  234.   /* minimal malloc checking is done, so intercept free() */
  235. # undef free
  236.   /*lint -save -e652 */
  237. # define free j_free
  238.   /*lint -restore */
  239. # ifdef J_FREE_HACK
  240.    void j_free (void *);
  241. # else
  242.    void j_free (const void *);
  243. # endif
  244. #else
  245. # define SRANDOM(n) srandom (n)
  246. # define RANDOM(n) ((int) (random() % (n)))
  247.   void *j_malloc (unsigned nb);
  248. # define malloc j_malloc
  249.   void j_free (const void *);
  250. # define free j_free
  251. # define strncmpi strnicmp
  252. # define strcmpi stricmp
  253. # define tnos_getdate getdate
  254. #endif
  255.  
  256.  
  257. int tputs (const char *s);
  258.  
  259. #ifndef NO_TNOSFOPEN
  260. # undef fopen
  261. # define fopen tnosfopen
  262. # undef fclose
  263. # define fclose tnosfclose
  264. # undef tmpfile
  265. # define tmpfile tnostmpfile
  266.  
  267.   FILE *tnosfopen (const char *fname, const char *mode);
  268.   int tnosfclose (FILE *stream);
  269.   FILE *tnostmpfile (void);
  270.  
  271. #endif
  272.  
  273. /* string equality shorthand */
  274. #define STREQ(x,y) (strcmp(x,y) == 0)
  275.  
  276. /* Extract a short from a long */
  277. #ifndef hiword
  278. #define    hiword(x)    ((int16)((x) >> 16))
  279. #endif
  280. #ifndef loword
  281. #define    loword(x)    ((int16)(x))
  282. #endif
  283.  
  284. /* Extract a byte from a short */
  285. #ifndef hibyte
  286. #define    hibyte(x)    ((unsigned char)((x) >> 8))
  287. #endif
  288. #ifndef lobyte
  289. #define    lobyte(x)    ((unsigned char)(x))
  290. #endif
  291.  
  292. /* Extract nibbles from a byte */
  293. #ifndef hinibble
  294. #define    hinibble(x)    (((x) >> 4) & 0xf)
  295. #endif
  296. #ifndef lonibble
  297. #define    lonibble(x)    ((x) & 0xf)
  298. #endif
  299.  
  300.  
  301. /* Various low-level and miscellaneous functions */
  302. int kpause (int32 ms);
  303. void *callocw (unsigned nelem,unsigned size);
  304. int disable (void);
  305. #ifdef UNIX
  306. int enable (void);
  307. #endif
  308. int atoip (char *);
  309. int htoi (const char *);
  310. long htol (char *);
  311. int16 hash_ip (uint32 addr);
  312. int istate (void);
  313. void log (int s,const char *fmt, ...);
  314. void simple_log (int s,const char *str);
  315. #ifdef MSDOS
  316. int log2 (int16 x);
  317. #endif
  318. void *mallocw (unsigned nb);
  319. void restore (int);
  320. void rflush (void);
  321. void rip (char *);
  322. const char *smsg (const char *msgs[],unsigned nmsgs,unsigned n);
  323. int wildmat (const char *s,char *p,char **argv);
  324. int tprintf (const char *fmt,...)
  325. #ifdef __GNUC__
  326.     __attribute__ ((format (printf, 1, 2)))
  327. #endif
  328.     ;
  329.  
  330. #ifdef TNOS_68K
  331. # include "osk.h"
  332. #endif
  333.  
  334. #ifdef UNIX
  335.   /* not sure how NOS will work with the GNU one... */
  336. # define ptol(p) ((long)(p))
  337.   /* can't do this above, GNU libc defines malloc to gnu_malloc in stdlib.h */
  338. # undef malloc
  339.   /*lint -save -e652 */
  340. # define malloc mallocw
  341.   /*lint -restore */
  342. #else
  343.   long ptol (void *);
  344. #endif
  345.  
  346.  
  347. /* General purpose function macros already defined in turbo C */
  348. #ifndef    min
  349. # define min(x,y)    ((x)<(y)?(x):(y))    /* Lesser of two args */
  350. #endif
  351.  
  352. #ifndef max
  353. # define max(x,y)    ((x)>(y)?(x):(y))    /* Greater of two args */
  354. #endif
  355.  
  356.  
  357. #ifdef sun
  358. # define SEEK_SET 0
  359. # define SEEK_CUR 1
  360. # define SEEK_END 2
  361.   extern char *sys_errlist[];
  362. # define memmove(s,d,l) bcopy((d),(s),(l))
  363. # define strerror(n) sys_errlist[(n)]
  364. #endif
  365.  
  366. #ifndef _ERRNO_H
  367. #include <errno.h>
  368. #endif
  369.  
  370.  
  371. #ifdef BROKE_SPRINTF
  372. # define SPRINTF(x) (int)strlen(sprintf x)
  373. # define VSPRINTF(x) (int)strlen((char *)vsprintf x)
  374. #else
  375. # define SPRINTF(x) sprintf x
  376. # define VSPRINTF(x) vsprintf x
  377. #endif
  378.  
  379. /* Externals used by getopt */
  380. extern int optind;
  381. extern char *optarg;
  382.  
  383.  
  384. #ifndef UNIX
  385.   /* Threshold setting on available memory */
  386.   extern int32 Memthresh;
  387. # ifndef OPTIONAL
  388. #  define OPTIONAL
  389. # endif
  390. #endif
  391.  
  392. /* System clock - count of ticks since startup */
  393. extern volatile int32 Clock;
  394.  
  395. /* Various useful standard error messages */
  396. extern char Badhost[];
  397. extern char Badinterface[];
  398. extern char Existingiface[];
  399. extern char Nospace[];
  400. extern char Notval[];
  401. extern char Version[];
  402. extern char Nosversion[];
  403. extern char *Hostname;
  404.  
  405. /* Your system's end-of-line convention */
  406. extern const char Eol[];
  407.  
  408. #ifdef UNIX
  409.   /* PCs have a few pseudo-"standard" library functions used by NOS */
  410.   extern char *stpcpy (char *, const char *);        /*lint !e762 */
  411.   extern char *strlwr (char *);
  412.   extern char *strupr (char *);
  413.   extern char *itoa (int, char *, int);
  414. #else
  415.   extern void (*Gcollect[]) (int);
  416. #endif
  417.  
  418.  
  419. #ifdef M_UNIX
  420. /*
  421.  * I am unsure of these; the i386 contents are not documented in 3.2.2.  I
  422.  * guessed at them by comparing "info regs" with the contents of a jmp_buf
  423.  * immediately after a setjmp().
  424.  */
  425. #define TNOS_PC(p) (p->env[5])
  426. #define TNOS_SP(p) (p->env[4])
  427. #define TNOS_BP(p) (p->env[3])
  428. #endif
  429.  
  430.  
  431. /* Your system OS - set in files.c */
  432. extern const char System[];
  433.  
  434. /* I know this is cheating, but it definitely makes sure that
  435.  * each module has config.h included ! - WG7J
  436.  */
  437. #ifndef _CONFIG_H
  438. # include "config.h"
  439. #endif
  440.  
  441. #ifdef UNIX
  442. # ifndef _UNIXTM_H
  443.   /* this is separate so unix.c can load it without global.h */
  444. #  include "unixtm.h"
  445. # endif
  446. #endif
  447.  
  448. int getopt (int argc,char * const *argv,const char *opts);
  449.  
  450. /* in main.c  */
  451. void where_outta_here (int resetme, char const *where);
  452.  
  453.                          
  454. #endif    /* _GLOBAL_H */
  455.